package solitaire.gui;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
//import solitaire.deck.CardCollection;
import solitaire.deck.Card;
import solitaire.deck.Deck;
import solitaire.deck.Card.Rank;
import solitaire.deck.Card.Suit;
import solitaire.extras.DrawObject;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MouseFrame extends javax.swing.JFrame {
	private static final long serialVersionUID = 123;
	private JMenuBar mainJMenuBar;
	private JMenu fileJMenu;
	private JMenu helpJMenu;
	private JMenuItem aboutMenuItem;
	private JMenuItem rulesMenuItem;
	private JMenuItem quitJMenuItem;
	private JMenuItem newSolitaireMenuItem;


	public static final int WIDTH = 800;
	public static final int HEIGHT = 600;
	public enum DrawObjectType{Box, Image}
	private final MousePanel panel = new MousePanel();
	/*
	* This is the main method that displays the JFrame.
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MouseFrame inst = new MouseFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	} 

	/*
	 * This is the JFrame that uses the predefined JFrame assets and initiates the initGUI function.
	 */
	
	public MouseFrame() {
		initGUI();
		
        Container contentPane = getContentPane();
        contentPane.add(panel);
        
	}

	/*
	 * This is the GUI initiation function. It throws an error Exception if there is a problem with
	 * any of the components that are to be drawn.
	 */
	private void initGUI() {
		try {
			window(); //The size of the window when you run the program
			fileMenuBar(); //The bar containing "File"
			helpMenuBar(); //The bar containing "Help"

			pack();	//To set the size of the program vs screen resolution
			
	        setSize( WIDTH, HEIGHT );
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/*
	 * This is the window function. It only adds the possibility of disposing of the window on close.
	 */
	private void window(){
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	}

	/*
	 *
	 * This GUI function draws the menu bar itself and adds the "File" menuItem to the bar.
	 * It also runs the functions that add the "New Solitaire" and the "Quit" item to the "File" menu.
	 *
	 */
	private void fileMenuBar(){
		mainJMenuBar = new JMenuBar();
		setJMenuBar(mainJMenuBar);
		fileJMenu = new JMenu();
		mainJMenuBar.add(fileJMenu);
		fileJMenu.setText("File");
		fileJMenu.setPreferredSize(new java.awt.Dimension(35, 21));
		fileNewMenuItem();
		fileRestartSolitaireItem();

		fileQuitMenuItem();
	}

	/*
	 *
	 * This GUI function draws the "New Solitaire" menuItem, initiated by the "File" menu.
	 *
	 */
	
	
	private void fileNewMenuItem(){
		newSolitaireMenuItem = new JMenuItem();
		fileJMenu.add(newSolitaireMenuItem);
		newSolitaireMenuItem.setText("New Solitaire");
		newSolitaireMenuItem.setBounds(0, 0, 35, 20);
		newSolitaireMenuItem.addActionListener(new AbstractAction( "Box" )
		{ public void actionPerformed( ActionEvent e )
			{ 
			  panel.newGame(true);
			  repaint();
			}
		} 
		);
	}

	/*
	 *

	/*
	 *
	 * This GUI function draws the "Restart Solitaire" menuItem, initiated by the "File" menu and restarts solitaire.
	 *
	 */
	private void fileRestartSolitaireItem(){
		newSolitaireMenuItem = new JMenuItem();
		fileJMenu.add(newSolitaireMenuItem);
		newSolitaireMenuItem.setText("Restart Solitaire");
		newSolitaireMenuItem.setBounds(0, 0, 35, 20);
		newSolitaireMenuItem.addActionListener(new AbstractAction( "Box" )
		{ public void actionPerformed( ActionEvent e )
			{ 
			  panel.newGame(false);
			  repaint();
			}
		} 
		);
	}

	/*
	 *
	 * This GUI function draws the "Quit" menuItem, initiated by the "File" menu.
	 *
	 */
	private void fileQuitMenuItem(){
		quitJMenuItem = new JMenuItem();
		fileJMenu.add(quitJMenuItem);
		quitJMenuItem.setText("Quit");
		quitJMenuItem.setBounds(0, 0, 33, 20);
		quitJMenuItem.addActionListener(new AbstractAction( "Box" )
		{ public void actionPerformed( ActionEvent e )
		{ System.exit(0); }} );
		
	}
	
	/*
	 *
	 * This GUI function adds the "Help" menu to the menuBar.
	 * It also initiates the functions to draw the "Help" and the "About" menu items to the Help menu.
	 *
	 */
	private void helpMenuBar(){
		helpJMenu = new JMenu();
		mainJMenuBar.add(helpJMenu);
		helpJMenu.setText("Help");
		helpJMenu.setPreferredSize(new java.awt.Dimension(40, 23));
		helpRulesMenuItem();
		aboutRulesMenuItem();
	}

	/*
	 *
	 * This GUI function draws the "Rules" menu item to the "Help" menu.
	 *
	 */
	private void helpRulesMenuItem(){
		rulesMenuItem = new JMenuItem();
		helpJMenu.add(rulesMenuItem);
		rulesMenuItem.setText("Rules");
		rulesMenuItem.setBounds(0, 0, 39, 19);
		rulesMenuItem.addActionListener(new AbstractAction("Box")
							{ public void actionPerformed( ActionEvent e )
								{ JOptionPane.showMessageDialog(null, "Rules for Granny's solitaire\n\n"
												+ "Pile the cards of a same suit in a descending order upwards. \n"
												+ "You can only put kings in the empty spaces and flip the \n"
												+ "facedown cards over if there is not a card ontop of them.\n"
												+ "Aces are to be placed in the four piles in the upright corner\n"
												+ "of the screen. To finish the solitaire you will have to empty \n"
												+ "the piles and place all them on top of the aces in an ascending order.\n");}} );
	}

	/*
	 *
	 * This GUI function draws the "About" menu item to the "Help" menu.
	 *
	 */
	private void aboutRulesMenuItem(){
		aboutMenuItem = new JMenuItem();
		helpJMenu.add(aboutMenuItem);
		aboutMenuItem.setText("About");
		aboutMenuItem.setBounds(0, 0, 39, 20);
		aboutMenuItem.addActionListener(new AbstractAction( "Box" )
							{ public void actionPerformed( ActionEvent e )
								{ JOptionPane.showMessageDialog(null, "Granny's Solitaire version 1.0"); }} );
	}
}